package cn.sangedon.review.analysis.mapper;

import cn.sangedon.review.common.domain.analysis.StockStastics;
import cn.sangedon.review.common.domain.analysis.StockStrategyResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Select;

/**
 * @author dongliangqiong
 * @description 针对表【tb_stock_stastics(股票统计信息表)】的数据库操作Mapper
 * @createDate 2022-09-22 14:03:25
 * @Entity cn.sangedon.review.analysis.domain.StockStastics
 */
public interface StockStasticsMapper extends BaseMapper<StockStastics> {

    @Select("SELECT trade_date FROM tb_stock_stastics LIMIT 1;")
    String getStasticsDate();

    @Select("SELECT * FROM tb_stock_stastics WHERE rise_day = 1 AND reduce_volume_day > 0 AND trade_date = (SELECT MAX(trade_date) FROM " +
            "tb_stock_stastics) ORDER BY reduce_volume_day DESC")
    List<StockStastics> continuousShrinkRise();

    @Select("SELECT * FROM tb_stock_stastics WHERE trade_date = (SELECT MAX(trade_date) FROM tb_stock_stastics)")
    List<StockStastics> listLatest();

    @Select("SELECT * FROM tb_stock_stastics WHERE rise_day > 1 AND enlarge_volume_day > 1 AND trade_date = (SELECT MAX(trade_date) FROM " +
            "tb_stock_stastics) ORDER BY enlarge_volume_day DESC, rise_day DESC")
    List<StockStastics> continuousHignVolumeRise();

    @Select("SELECT t.stock_code as stockCode , t.stock_name as stockName , p.trade_date as tradingDate FROM (SELECT * FROM " +
            "tb_stock_stastics WHERE fall_day >= 2 AND trade_date = #{preTradeDate}) t LEFT JOIN (SELECT * FROM tb_stock_stastics WHERE " +
            "rise_day = 1 AND reduce_volume_day > 0 AND trade_date = #{tradeDate}) p ON p.stock_code = t.stock_code WHERE p.stock_code IS" +
            " NOT NULL AND (t.stock_code LIKE '60%' OR t.stock_code LIKE '00%') ORDER BY t.fall_day DESC")
    List<StockStrategyResult> fallShrinkRed(String preTradeDate, String tradeDate);

    @Select("SELECT * FROM tb_stock_stastics WHERE fall_day >= #{fallDays} AND trade_date = (SELECT MAX(trade_date) FROM " +
            "tb_stock_stastics)")
    List<StockStastics> continuousFall(Integer fallDays);
}




